package v1

import (
	"github.com/gin-gonic/gin"
	"maya-service/bll/weixin"
	"maya-service/utils"
)

var ThirdPart = &thirdPart{}

func init() {
	RegisterRouter(ThirdPart)
}

type thirdPart struct{}

// Init
func (a *thirdPart) Init(r *gin.RouterGroup) {
	g := r.Group("/thirdPart")
	{
		// 获取用户企业微信用户身份
		g.POST("/getUserIdentity", a.getUserIdentity)
	}
}

// create
func (a *thirdPart) getUserIdentity(c *gin.Context) {
	type Req struct {
		Code string `json:"code"`
	}

	type Rsp struct {
		UserId     string `json:"user_id"`
		UserTicket string `json:"user_ticket"`
	}
	var (
		in  = &Req{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	// 获取身份信息
	userId, userTicket, err := weixin.GetUserIdentityByCode(in.Code)
	utils.ResponseOk(c, &Rsp{
		UserId:     userId,
		UserTicket: userTicket,
	})
}
